#include "bbh_output_std.h"

#include "bbh_include.h"

#include "bbh_output.h"

struct bbh_output_std_s
{
    int id;
};

static int  bbh_output_std_open(const char*s, size_t len, void**pptr)
{
    struct bbh_output_std_s *p;

    p = (struct bbh_output_std_s*)malloc(sizeof(struct bbh_output_std_s));
    if (!p)
        return -1;
    memset(p, 0, sizeof(struct bbh_output_std_s));

    *pptr = p;

    return 0;
}
static int  bbh_output_std_write(void*_, const char*s, size_t len)
{
    return (int)fwrite(s, 1, len, stderr);
}
static int  bbh_output_std_print(void*_, const char*fmt, ...)
{
    int r = 0;
    va_list ap;
    va_start(ap, fmt);
    r = vfprintf(stderr, fmt, ap);
    va_end(ap);
    return r;
}
static void bbh_output_std_flush(void*_)
{
}
static void bbh_output_std_close(void*_)
{
    struct bbh_output_std_s*out = (struct bbh_output_std_s*)_; 
    free(out);
}

static struct bbh_output_s output_std_driver = {
    output_type_stdout,
    "stdout",
    bbh_output_std_open,
    bbh_output_std_write,
    bbh_output_std_print,
    bbh_output_std_flush,
    bbh_output_std_close
};

struct bbh_output_s*  bbh_output_std_driver()
{
    return &output_std_driver;
}